//
//  ToutiaoModel.m
//  WangI
//
//  Created by 陈曦 on 15/11/23.
//  Copyright © 2015年 WJN. All rights reserved.
//

#import "ToutiaoModel.h"

@implementation ToutiaoModel

-(void)dealloc {
    [_title release];
    [_imgsrc release];
    [_digest release];
    [_adss release];
    [_replyCount release];
    [_imagearray release];
    [super dealloc];
}

-(instancetype)initWithDic:(NSDictionary *)dic {
    self = [super init];
    if (self) {
        [self setValuesForKeysWithDictionary:dic];
    }
    return self;
}

-(void)setValue:(id)value forUndefinedKey:(NSString *)key {
//    adsmodel纠错
    if ([key isEqualToString:@"ads"]) {
        NSMutableArray *array1 = [[NSMutableArray alloc] init];
        NSArray *array = value;
        for (NSDictionary *dic in array) {
            AdsModel *ads = [[AdsModel alloc] initWithDic:dic];
            [array1 addObject:ads];
            [_adss release];
        }
        self.adss = array1;
        [_adss release];
    }
//    两张图片存到数组里
    if ([key isEqualToString:@"imgextra"]) {
        NSArray *array = value;
        NSMutableArray *array2 = [[NSMutableArray alloc] init];
        for (NSDictionary *dic in array) {
            NSString *image = [dic valueForKey:@"imgsrc"];
            [array2 addObject:image];
        }
        self.imagearray = array2;
    }
}

-(id)valueForUndefinedKey:(NSString *)key {
    return nil;
}

@end
